﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Active.Core;

namespace Active.Controls
{
    /// <summary>
    /// BillState 的摘要说明
    /// </summary>
    public class BillState : Control
    {
        private Bill _Bill;
        public Bill Bill
        {
            get
            {
                return _Bill;
            }
            set {
                _Bill = value;
            }
        }

        private static readonly string BillInfoFormatSTRING = @"
<label>清单编号: </label><a href='{8}Bill/Order.aspx?BillId={0}' title='点击查看'><span class='infoColumn'>{1}</span></a>
<label>代理: </label><a href='{2}'><span class='infoColumn'>{3}</span></a>
<label>客户: </label><a href='{4}'><span class='infoColumn'>{5}</span></a>
<label>产品: </label><a href='{6}'><span class='infoColumn'>{7}</span></a>";

        protected override void Render(HtmlTextWriter writer)
        {
            if (Bill == null)
                return;
            writer.AddAttribute("class", "billInfo");
            writer.RenderBeginTag(HtmlTextWriterTag.Fieldset);
            writer.RenderBeginTag(HtmlTextWriterTag.Legend);
            writer.Write(string.Format("<a href='{0}Bill/Order.aspx?BillId={1}' title='点击查看'>清单信息</a>", Utils.RelativeWebRoot, Bill.Id));
            if (Utils.IsGeneralManager || Utils.IsMediaManager)
            {
                writer.Write(string.Format(" - <a href='{0}BalanceTable.aspx?BillId={1}' title='点击查看'>收支平衡表</a>", Utils.RelativeWebRoot, Bill.Id));
            }
            writer.RenderEndTag();

            writer.Write("<h6>信息:</h6>");

            writer.AddAttribute("class", "info");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.Write(string.Format(BillInfoFormatSTRING,
               Bill.Id,
               Bill.Number,
               Bill.AgentId > 0 ? string.Format(VirtualPathUtility.ToAbsolute("~/Customer/AddAgent.aspx")
               + "?AgentId={0}", Bill.AgentId) : "#",
               Bill.AgentId > 0 ? Bill.Agent.Name : "无",
               string.Format(VirtualPathUtility.ToAbsolute("~/Customer/AddCustomer.aspx")
               + "?CustomerId={0}", Bill.CustomerId),
               Bill.Customer.Name,
               string.Format(VirtualPathUtility.ToAbsolute("~/Customer/AddProduct.aspx")
               + "?CustomerId={0}", Bill.CustomerId),
               Bill.ProductName,
               Utils.RelativeWebRoot));

            writer.Write(string.Format("<label>投放日期: </label><span class='infoColumn'>{0}</span>",
                        Formater.GetCampaignPeriodDaysHTML(Bill.StartDate.Date, Bill.EndDate.Date)));
            writer.RenderEndTag();

            writer.Write("<h6>处理状态:</h6>");

            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.AddAttribute("class", "auditState");
            writer.RenderBeginTag(HtmlTextWriterTag.Span);
            writer.Write("<label>客户部:</label>");
            Image imageCustomerEmployeeAudit = new Image();
            //imageCustomerEmployeeAudit.ImageUrl = string.Format("~/pics/Audit{0}.png", Bill.CustomerEmployeeAudit);
            //imageCustomerEmployeeAudit.AlternateText = Utils.GetAuditString(Bill.CustomerEmployeeAudit);
            imageCustomerEmployeeAudit.RenderControl(writer);
            writer.RenderEndTag();

            writer.AddAttribute("class", "auditState");
            writer.RenderBeginTag(HtmlTextWriterTag.Span);
            writer.Write("<label>客户部总监:</label>");
            Image imageCustomerManagerAudit = new Image();
            //imageCustomerManagerAudit.ImageUrl = string.Format("~/pics/Audit{0}.png", Bill.CustomerManagerAudit);
            //imageCustomerManagerAudit.AlternateText = Utils.GetAuditString(Bill.CustomerManagerAudit);
            imageCustomerManagerAudit.RenderControl(writer);
            writer.RenderEndTag();

            writer.AddAttribute("class", "auditState");
            writer.RenderBeginTag(HtmlTextWriterTag.Span);
            writer.Write("<label>媒介部:</label>");
            Image imageMediaEmployeeAudit = new Image();
            //imageMediaEmployeeAudit.ImageUrl = string.Format("~/pics/Audit{0}.png", Bill.MediaEmployeeAudit);
            //imageMediaEmployeeAudit.AlternateText = Utils.GetAuditString(Bill.MediaEmployeeAudit);
            imageMediaEmployeeAudit.RenderControl(writer);
            writer.RenderEndTag();

            writer.AddAttribute("class", "auditState");
            writer.RenderBeginTag(HtmlTextWriterTag.Span);
            writer.Write("<label>媒介部总监:</label>");
            Image imageMediaManagerAudit = new Image();
            //imageMediaManagerAudit.ImageUrl = string.Format("~/pics/Audit{0}.png", Bill.MediaManagerAudit);
            //imageMediaManagerAudit.AlternateText = Utils.GetAuditString(Bill.MediaManagerAudit);
            imageMediaManagerAudit.RenderControl(writer);
            writer.RenderEndTag();

            writer.AddAttribute("class", "auditState");
            writer.RenderBeginTag(HtmlTextWriterTag.Span);
            writer.Write("<label>总经理:</label>");
            Image imageGeneralManagerAudit = new Image();
            //imageGeneralManagerAudit.ImageUrl = string.Format("~/pics/Audit{0}.png", Bill.GeneralManagerAudit);
            //imageGeneralManagerAudit.AlternateText = Utils.GetAuditString(Bill.GeneralManagerAudit);
            imageGeneralManagerAudit.RenderControl(writer);
            writer.RenderEndTag();

            writer.AddAttribute("class", "auditState");
            writer.RenderBeginTag(HtmlTextWriterTag.Span);
            writer.Write("<label>财务部:</label>");
            Image imageFinanceAudit = new Image();
            //imageGeneralManagerAudit.ImageUrl = string.Format("~/pics/Audit{0}.png", Bill.FinanceAudit);
            //imageGeneralManagerAudit.AlternateText = Utils.GetAuditString(Bill.FinanceAudit);
            imageGeneralManagerAudit.RenderControl(writer);
            writer.RenderEndTag();

            writer.RenderEndTag();
            writer.RenderEndTag();
        }
    }
}
